﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
using System.Configuration;

namespace devtm.Editor.Configuration
{
    public partial class UCConfigEdit
    {

        protected void InitializeCommandBindings()
        {


            CommandBindings.Add(new CommandBinding(ApplicationCommands.Undo, OnUndoCommand, CommandUndo_CanExecute));
            CommandBindings.Add(new CommandBinding(ApplicationCommands.Redo, OnRedoCommand, CommandRedo_CanExecute));
            

            CommandBindings.Add(new CommandBinding(UCConfigEditCommands.AddSection, OnAddSectionCommand, CommandAddSection_CanExecute));
            CommandBindings.Add(new CommandBinding(UCConfigEditCommands.DelSection, OnDelSectionCommand, CommandDelSection_CanExecute));

            CommandBindings.Add(new CommandBinding(UCConfigEditCommands.AddItem, OnAddItemCommand, CommandAddItem_CanExecute));
            CommandBindings.Add(new CommandBinding(UCConfigEditCommands.DelItem, OnDelItemCommand, CommandDelItem_CanExecute));
            CommandBindings.Add(new CommandBinding(UCConfigEditCommands.EditItem, OnEditItemCommand, CommandEditItem_CanExecute));

            // tools
            CommandBindings.Add(new CommandBinding(UCConfigEditCommands.Merge, OnMergeCommand, CommandMerge_CanExecute));
         
            CommandBindings.Add(new CommandBinding(ApplicationCommands.Cut, OnCutCommand, CommandCut_CanExecute ));
            CommandBindings.Add(new CommandBinding(ApplicationCommands.Copy, OnCopyCommand, CommandCopy_CanExecute));
            CommandBindings.Add(new CommandBinding(ApplicationCommands.Paste, OnPasteCommand, CommandPaste_CanExecute));

            
        }



        #region Command

        private void CommandUndo_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = UCConfigEdit.ConfigEdit.CanUndo;
            if (e.CanExecute == false)
                e.ContinueRouting = false;
        }
        private void OnUndoCommand(object sender, ExecutedRoutedEventArgs e)
        {
            UCConfigEdit.ConfigEdit.Undo();
        }


        private void CommandRedo_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {

            e.CanExecute = UCConfigEdit.ConfigEdit.CanRedo;

            if (e.CanExecute == false)
                e.ContinueRouting = false;

        }
        private void OnRedoCommand(object sender, ExecutedRoutedEventArgs e)
        {
            UCConfigEdit.ConfigEdit.Redo();
        }

        #endregion

        #region Section

        private void CommandAddSection_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = true;
            if (e.CanExecute == false)
                e.ContinueRouting = false;
        }
        private void OnAddSectionCommand(object sender, ExecutedRoutedEventArgs e)
        {
            UCConfigEdit.ConfigEdit.AddSection();
        }


        private void CommandDelSection_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {

            e.CanExecute = UCConfigEdit.ConfigEdit.SectionCanRemove;

            if (e.CanExecute == false)
                e.ContinueRouting = false;

        }
        private void OnDelSectionCommand(object sender, ExecutedRoutedEventArgs e)
        {
            UCConfigEdit.ConfigEdit.RemoveSection();
        }

        #endregion

        #region Item

        private void CommandDelItem_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {

            e.CanExecute = UCConfigEdit.ConfigEdit.ItemCanRemove;

            if (e.CanExecute == false)
                e.ContinueRouting = false;

        }
        private void OnDelItemCommand(object sender, ExecutedRoutedEventArgs e)
        {
            UCConfigEdit.ConfigEdit.RemoveSection();
        }


        private void CommandAddItem_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {

            e.CanExecute = UCConfigEdit.ConfigEdit.ItemCanAdd;

            if (e.CanExecute == false)
                e.ContinueRouting = false;

        }
        private void OnAddItemCommand(object sender, ExecutedRoutedEventArgs e)
        {
            UCConfigEdit.ConfigEdit.AddItem();
        }


        private void CommandEditItem_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {

            e.CanExecute = UCConfigEdit.ConfigEdit.ItemCanEdit;

            if (e.CanExecute == false)
                e.ContinueRouting = false;

        }
        private void OnEditItemCommand(object sender, ExecutedRoutedEventArgs e)
        {
            UCConfigEdit.ConfigEdit.EditItem();
        }


        private void CommandMerge_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {

            e.CanExecute = UCConfigEdit.ConfigEdit.ItemCanMerge;

            if (e.CanExecute == false)
                e.ContinueRouting = false;

        }

    
        private void OnMergeCommand(object sender, ExecutedRoutedEventArgs e)
        {
            UCConfigEdit.ConfigEdit.MergeCurrentSection();
        }
       
        #endregion

        #region clipboard

        private void CommandCut_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {

            e.CanExecute = UCConfigEdit.ConfigEdit.ClipboardCanCut;

            if (e.CanExecute == false)
                e.ContinueRouting = false;

        }
        private void OnCutCommand(object sender, ExecutedRoutedEventArgs e)
        {
            UCConfigEdit.ConfigEdit.ClipboardCut();
        }


        private void CommandCopy_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {

            e.CanExecute = UCConfigEdit.ConfigEdit.ClipboardCanCut;

            if (e.CanExecute == false)
                e.ContinueRouting = false;

        }
        private void OnCopyCommand(object sender, ExecutedRoutedEventArgs e)
        {
            UCConfigEdit.ConfigEdit.ClipboardCopy();
        }


        private void CommandPaste_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {

            e.CanExecute = System.Windows.Clipboard.ContainsData(UCConfigEdit.ClipboardFormat);

            if (e.CanExecute == false)
                e.ContinueRouting = false;

        }
        private void OnPasteCommand(object sender, ExecutedRoutedEventArgs e)
        {
            UCConfigEdit.ConfigEdit.ClipboardPaste();
        }

        #endregion

    }
}
